<?php

class Default_TagController extends Ext_Controller_Action_Front
{
    public function init()
    {
        parent::init();
    }

    public function preDispatch() 
    {
        parent::preDispatch();
        
        $userId = Ext_Auth_Front::getInstance()->getIdentity();
        $roleId = Ext_User::getInstance()->show($userId)->buildRole()->role->roleId;
        $acl = Ext_Acl::getInstance()->build($roleId);
        if(!$acl->isAllowed($roleId, 'index', 'view')){
            $this->_forward("show-access-denied", "auth", "account");
            return false;
        }
    }
    
    public function hotAction()
    {

        $strTime = "m6";
        $num = 20;
        
        if(preg_match("/Y([0-9]+)/si", $strTime, $m) && $m)
        {
            $time = time()-$m['1']*360*24*60*60;
        }
        elseif(preg_match("/m([0-9]+)/si", $strTime, $m) && $m)
        {
            $time = time()-$m['1']*30*24*60*60;
        }
        elseif(preg_match("/d([0-9]+)/si", $strTime, $m) && $m)
        {
            $time = time()-$m['1']*24*60*60;
        }
        elseif(preg_match("/H([0-9]+)/si", $strTime, $m) && $m)
        {
            $time = time()-$m['1']*60*60;
        }
        elseif(preg_match("/i([0-9]+)/si", $strTime, $m) && $m)
        {
            $time = time()-$m['1']*60;
        }
        else
        {
            $time = 60*24;
        }
        
        $num = intval($num);
        
        $hotTags = App_Model_DbTable_Tag_History::getInstance()->getHot($time, $num);
        foreach ($hotTags as $key=>$hotTag)
        {
            $tagId = $hotTag['tagId'];
            $tagOne = App_Model_DbTable_Tags::getInstance()->getRowById($tagId);
            if($tagOne)
            {
                $hotTag['tag'] = new Ext_Tag_Show($tagOne['id']);
            }
            
            $hotTags[$key] = $hotTag;
        }
        
        $this->view->hotTags = $hotTags;
    }
}

?>